﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MoonLight.LibCommon;
using Autumn.Common;

namespace Autumn.NetSession
{
    class SessionManager : Notifier
    {
        public SessionManager()
        {
            m_sess_list = new List<AuSession>();
        }

        public void AddSession(AuSession sess)
        {
            m_sess_list.Add(sess);
        }

        public void DelSession(AuSession sess)
        {
            for (int i = 0; i < m_sess_list.Count; i++)
            {
                if (m_sess_list[i].GetSessionId().GetId() == sess.GetSessionId().GetId()) 
                {
                    Logger.WriteLog("session[" + sess.GetSessionId().GetId() + "] deleted");
                    m_sess_list.RemoveAt(i);
                }
            }
        }

        public void DelAllSession()
        {
            for (int i = 0; i < m_sess_list.Count; i++)
            {
                m_sess_list[i].Close();
            }
            m_sess_list.Clear();
        }

        private List<AuSession> m_sess_list;
    }
}
